package com.migo.controller;

import com.migo.entity.SysUserEntity;
import com.migo.entity.TechnicalSupportTypeEntity;
import com.migo.service.SysUserService;
import com.migo.service.TechnicalSupportTypeService;
import com.migo.utils.PageUtils;
import com.migo.utils.Query;
import com.migo.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

import static com.migo.utils.ShiroUtils.getUserId;


/**
 * 技术支持类型添加
 * 
 * @author powervision
 * @email wes.wang@powervision.me
 * @date 2018-12-18 12:04:01
 */
@RestController
@RequestMapping("technicalsupporttype")
public class TechnicalSupportTypeController {
	@Autowired
	private TechnicalSupportTypeService technicalSupportTypeService;


	@Autowired
	private SysUserService sysUserService;
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("technicalsupporttype:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<TechnicalSupportTypeEntity> technicalSupportTypeList = technicalSupportTypeService.queryList(query);
		int total = technicalSupportTypeService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(technicalSupportTypeList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}


	/**
	 * 技术支持类型列表
	 */
	@RequestMapping("/supportList")
	@RequiresPermissions("technicalsupporttype:supportList")
	public R proList(@RequestParam Map<String, Object> params) {
		//查询列表数据
		List<TechnicalSupportTypeEntity> technicalSupportTypeList  = technicalSupportTypeService.queryList(params);
		return R.ok().put("supportList", technicalSupportTypeList);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("technicalsupporttype:info")
	public R info(@PathVariable("id") Integer id){
		TechnicalSupportTypeEntity technicalSupportType = technicalSupportTypeService.queryObject(id);
		
		return R.ok().put("technicalSupportType", technicalSupportType);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("technicalsupporttype:save")
	public R save(@RequestBody TechnicalSupportTypeEntity technicalSupportType){
		SysUserEntity user = sysUserService.queryObject(getUserId());
		technicalSupportType.setAddUser(user.getUsername());
		technicalSupportTypeService.save(technicalSupportType);
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("technicalsupporttype:update")
	public R update(@RequestBody TechnicalSupportTypeEntity technicalSupportType){
		technicalSupportTypeService.update(technicalSupportType);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("technicalsupporttype:delete")
	public R delete(@RequestBody Integer[] ids){
		technicalSupportTypeService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
